package com.zut.hospital.controller.pharmacy;

import com.alibaba.fastjson.JSONObject;
import com.zut.hospital.service.pharmacy.MedicineService;
import com.zut.hospital.service.pharmacy.SaleRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @program: hos-test
 * @description:
 * @author: 杨曼珍
 * @create: 2019-07-01 11:16
 **/
@Controller
@RequestMapping("/hospital")
public class MedicineController {
    private static final Logger log = LoggerFactory.getLogger(MedicineController.class);
    @Autowired
    MedicineService medicineService;

    @ResponseBody
    @RequestMapping(value = "/medicine/name",produces = "application/json;charset=utf-8",method = RequestMethod.POST)
    public String findMedByMedNameConsole(@RequestBody String data){
        log.info(data);
        log.info("key"+JSONObject.parseObject(data).getString("keywords"));
        String key = JSONObject.parseObject(data).getString("keywords");
        log.info("key"+key);
        System.out.println(key);
        return medicineService.findMedByMedNameConsole(key);
    }

    @ResponseBody
    @RequestMapping(value = "/medicine/page")
    public String pageMed(@RequestParam("page")int page,
                                          @RequestParam("limit")int limit){
        return medicineService.pageallMed(page,limit);
    }

    @ResponseBody
    @RequestMapping(value = "/medicine/update")
    public String pageMed(@RequestBody String data){
        int id = JSONObject.parseObject(data).getInteger("id");


        String field = JSONObject.parseObject(data).getString("field");
        String value = JSONObject.parseObject(data).getString("value");
        return medicineService.updateMed(id,field,value);
    }

}
